package com.sysmind.ravi.margin.utils;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class JDBCHelper 
{	private Connection conn;

	public Connection getConnection()
	{	conn = null;
	
		String url = "jdbc:oracle:thin:@10.50.1.47:1521:";
	    String dbName = "orcl";
	    String driver = "oracle.jdbc.OracleDriver";
	    String userName = "scott"; 
	    String password = "tiger";
		try
		{	try 
			{
				Class.forName(driver);	

			} catch(java.lang.ClassNotFoundException e) 
			{
				System.err.print("ClassNotFoundException: ");
				System.err.println(e.getMessage());
			}

			
			//Class.forName(driver);
			//String url = ;
			conn = DriverManager.getConnection(url+dbName,userName,password);
			conn.setAutoCommit(false);
			//System.out.println("success");
		
			//Connection con=null;
		      //Class.forName("oracle.jdbc.driver.OracleDriver");
		      //con=DriverManager.getConnection(
		       // "jdbc:oracle:thin:@machine_name:1521:database_name",
		       // "scott",
		        //"tiger");

		}
		catch(SQLException ex)
		{
			ex.printStackTrace();
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
		
		return conn;
	}

	public void closeConnection()
	{
		try
		{
			if(conn!=null && conn.isClosed())
			{
				conn.close();
			}
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
	}
	
	/*
	public static void main(String args[])	 
	{	JDBCHelper jdbc =  new JDBCHelper();
		
		Connection conn = jdbc.getConnection();
		
	}
	*/

}
